package modeller.queueingnetworksmodel.structure;

import modeller.databasedesignmodel.relation.Relation;
import modeller.databasedesignmodel.transaction.*;
import org.jdom2.Element;

import java.text.DecimalFormat;
import java.util.HashSet;

import static queped.quepedconstants.Strings.*;

/**
 * Created by:  Jason Ye
 * Date:        30/05/2012
 * Time:        20:59
 */
public abstract class AbstractNodeChildElement implements IQueueingNetworkModelXMLNode {

    protected HashSet<Transaction> transactions;
    protected final DecimalFormat dpFormat = new DecimalFormat("#.##");
    protected Relation relation;

    public AbstractNodeChildElement(HashSet<Transaction> transactions, Relation relation) {
        this.transactions = transactions;
        this.relation=relation;
    }

    protected Element generateSubParam(String classPath, String name) {
        return generateSubParam(classPath,name,false);
    }

    protected Element generateSubParam(String classPath, String name, boolean isArray){
        Element subParam = generateNewParam(classPath, name, isArray);
        subParam.setName(XML_E_SUBPARAMETER);
        return subParam;
    }

    protected Element generateValueElem(String value) {
        Element val = new Element(XML_E_PARAMETER_VALUE);
        val.addContent(value);
        return val;
    }

    protected Element generateNewParam(String classPath, String name, boolean isArray) {
        Element size = new Element(XML_E_PARAMETER);
        size.setAttribute(XML_A_PARAMETER_CLASSPATH, classPath);
        size.setAttribute(XML_A_CLASS_NAME, name);
        if (isArray) {
            size.setAttribute(XML_A_SUBPARAMETER_ARRAY, "true");
        }

        return size;
    }

    protected Element generateNewRefClassElem(String transactionID) {
        Element ret = new Element(XML_E_PARAMETER_REFCLASS);
        ret.addContent(transactionID);
        return ret;
    }
}
